import Mock from "mockjs";

// 占位符 的格式为：
// @占位符
// @占位符(参数 [, 参数])

// 延时400s请求到数据
// Mock.setup({
//     timeout: 400
// })

// 延时200-600毫秒请求到数据
Mock.setup({
	timeout: "200-600"
});

Mock.mock("/api/lists", {
	ret: 0,
	data: {
		mtime: "@datetime", //随机生成日期时间
		"score|1-800": 800, //随机生成1-800的数字
		"rank|1-100": 100, //随机生成1-100的数字
		"stars|1-5": 5, //随机生成1-5的数字
		nickname: "@cname" //随机生成中文名字
	}
});

Mock.mock("/api/table/dataSource", {
	code: 0,
	"result|20": [
		{
			"key|+1": 1,
			name: "@cname",
			"age|20-40": 20,
			address: "西湖区湖底公园1号"
		}
	]
});

Mock.mock("/api/table/dataSource2", {
	code: 0,
	"result|5": [
		{
			"id|+1": 1,
			"key|+1": 0, //动态渲染时需要绑定一个key
			userName: "@cname",
			"sex|1-2": 1,
			"state|1-5": 1,
			"interest|1-4": 1,
			birthday: "2000-01-01",
			time: "09:00",
			"age|20-40": 20
		}
	]
});

// 通过正则的形式可以在 GET 请求下对请求进行拦截
Mock.mock(/\/api\/table\/standardDatas[\s\S]*?/, "get", {
	code: 0,
	message: "successful",
	result: {
		"lists|5": [
			{
				"id|+1": 1,
				userName: "@cname",
				"sex|1-2": 1,
				"state|1-5": 1,
				"interest|1-4": 1,
				birthday: "2000-01-01",
				time: "09:00",
				"age|20-40": 20,
				address: "西湖区湖底公园1号"
			}
		],
		current: 5,
		pageSize: 5,
		total: 100
	}
});

Mock.mock(/\/api\/city[\s\S]*?/, "get", {
	code: 0,
	message: "successful",
	result: {
		"lists|5": [
			{
				"id|+1": 1,
				cityName: "@city",
				"mode|1-2": 1,
				"op_mode|1-2": 1,
				franchisee_name: "@cname",
				"auth_status|1-2": 1,
				"city_admins|1-2": [
					{
						userName: "@cname",
						"userId|+1": 10001
					}
				],
				open_time: "@datetime",
				update_time: "@datetime"
			}
		],
		current: 5,
		pageSize: 5,
		total: 100
	}
});

Mock.mock(/\/api\/order[\s\S]*?/, "get", {
	code: 0,
	message: "successful",
	result: {
		"lists|5": [
			{
				"id|+1": 10000,
				order_sn: /T180[0-9]{6}/,
				bike_sn: /B980[0-9]{6}/,
				cityName: "@city",
				"user_id|+1": 990000,
				user_name: "@cname",
				mobile: /1[3578][0-9]{9}/,
				distance: "@natural( 1, 99 )",
				total_time: "@natural( 5, 30 )",
				total_fee: "@integer",
				"status|1-2": 1,
				start_time: "@datetime",
				end_time: "@datetime",
				user_pay: "@natural( 0, 10 )"
			}
		],
		current: 5,
		pageSize: 5,
		total: 100
	}
});
